# !/usr/bin/env python
# coding=utf-8
# @Time    : 2018/5/10 9:33
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/scrayp_test1.git
# @File    : dao.py
# @Software: PyCharm
# @Version: 2.7.5
from .models import Housing
from . import Session
from py3_utils import my_time, my_decorator


@my_decorator.handle_exception()
def insert_housing(*args, **kwargs):
	session = Session()
	try:
		project = Housing(project_name=args[0], project_uuid=args[1], project_district=args[2],
			                  create_time=my_time.get_now())
		session.add(project)
		session.commit()
	finally:
		session.remove()

@my_decorator.handle_exception()
def insert_housing2(*args, **kwargs):
	session = Session()
	session.execute(
		Housing.__table__.insert().prefix_with('IGNORE'),
		{'project_name': args[0], 'project_uuid': args[1],
		  'project_district': args[2], 'create_time': my_time.get_now()}
	)
	session.commit()
	# session.remove()